package model;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @author Thierry
 *
 */
public interface ISPGraph extends Serializable {

	/**
	 * Returns the set of vertexes that are in the SPGraph, even the
	 * isolated ones.
	 *
	 * @return the set of vertexes in the graph
	 */
	Set<IVertex> getVertexes();
	
	/**
	 * Returns the set of vertexes that has one
	 * or more edges leaving from it.
	 * 
	 * @return the set of departure vertexes
	 */
	Set<IVertex> getDepartureVertexes();
	
	/**
	 * 
	 * @param departureVertex - the departure vertex of an edge if it exists. 
	 * @param label - the label of the edge
	 * @return	the destination vertex, if it exists,leaving from
	 * 			departureVertex and labeled by label. Otherwise null is returned.		
	 */
	IVertex getTargetVertex(IVertex departureVertex, String label);
	
	/**
	 * 
	 * @return the codewords associated to the SPGraph 
	 */
	ICodeWords getCodeWords();
	
	/**
	 * Computes a new set and fill it with all predecessors of the vertex.
	 * @param vertex - the vertex from which we want to calculate 
	 * the set of predecessors
	 * @return the set of predecessors
	 */
	Set<IVertex> getVertexPredecessors(IVertex vertex);
	
	/**
	 * Computes a new set and fill it with all successors of the vertex.
	 * 
	 * @param vertex - the vertex from which we want to calculate
	 * the set of successors
	 * 
	 * @return the set of successors if they exists, null otherwise
	 */
	Set<IVertex> getVertexSuccessors(IVertex vertex);

	/**
	 * 
	 * @param departureVertex the departure vertex of the edge
	 * @param arrivalVertex the arrival vertex of the edge
	 * @return the label of the edge if it exists, null otherwise.
	 */
	String getEdgeLabel(IVertex departureVertex, IVertex arrivalVertex);
	
	/**
	 * Computes a map representation of the graph that maps the departure vertex
	 * to another map that maps the label of the edge with the destination vertex
	 * @return the map representation of the graph with the not isolated
	 * vertex
	 */
	Map<IVertex, Map<String, IVertex>> getGraphMap();
	
	/**
	 * Computes the decode delay and returns it.
	 * 
	 * @return the decode delay
	 */
	int decodeDelay();
	
	/**
	 * Translates a message coded with the
	 * current codeword
	 * 
	 * @param message the message to translate
	 * @return the message translated
	 */
	String translate(String message);
	
	/**
	 * Computes the free envelope and returns it.
	 * 
	 * @return the free envelope
	 */
	ICodeWords getFreeEnvelope();
	
	/**
	 * Removes the edge from the SPGraph.
	 * @param departureVertex - the departure vertex of the edge
	 * @param label - the label of the edge
	 * @param arrivalVertex - the arrival vertex of the edge
	 * @return true if the edge was removed, false otherwise.
	 */
	boolean removeEdge(IVertex departureVertex, String label, IVertex arrivalVertex);
	
	/**
	 * Indicates if this graph is synchronized
	 * with a file
	 * 
	 * @return true if it is synchronized, false otherwise
	 */
	boolean isSync();
	
	/**
	 * @param code - the codewords to be set
	 */
	void setCodeWords(ICodeWords code);
	
	/**
	 * Sets the synchronization value
	 * 
	 * @param sync
	 */
	void setSync(boolean sync);
	
	/**
	 * Saves the current ISPGraph
	 */
	void save();
	
}
